﻿using Abp.Net.Mail;
using Abp.UI;
using Mt.Site.Application.Configuration.Host.Dto;
using System;
using System.Threading.Tasks;

namespace Mt.Site.Application.Configuration
{
    public abstract class SettingsAppServiceBase : MtSiteAppServiceBase
    {
        private readonly IEmailSender _emailSender;

        protected SettingsAppServiceBase(
            IEmailSender emailSender)
        {
            _emailSender = emailSender;
        }

        #region Send Test Email

        public async Task SendTestEmail(SendTestEmailInput input)
        {
            try
            {
                await _emailSender.SendAsync(
                    input.EmailAddress,
                    L("TestEmail_Subject"),
                    L("TestEmail_Body")
                );
            }
            catch (Exception e)
            {
                throw new UserFriendlyException("An error was encountered while sending an email. " + e.Message, e);
            }
        }

        #endregion
    }
}
